package djy.scgcube.test1;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.media.MediaScannerConnection;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.content.ContextCompat;
import android.util.Log;
import android.view.View;
import com.unity3d.player.UnityPlayerActivity;

public class MainActivity extends UnityPlayerActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //设置状态栏为透明
//        View decorView = getWindow().getDecorView();
//        int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
//                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
//        decorView.setSystemUiVisibility(option);
//        getWindow().setNavigationBarColor(Color.TRANSPARENT);
//        getWindow().setStatusBarColor(Color.TRANSPARENT);

    }


    private String[] mPermissions1 = {Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
    };

    private String[] mPermissions2 = {Manifest.permission.CAMERA,
    };


    /**
     * 判断是否缺少权限
     */
    private static boolean lacksPermission(Context mContexts, String permission) {
        return ContextCompat.checkSelfPermission(mContexts, permission) ==
                PackageManager.PERMISSION_DENIED;
    }

    public int add(int a, int b) {
        return a + b;
    }

//    是否获取了定位权限
    public boolean IsDingWeiPermissionHave() {
        if (Build.VERSION.SDK_INT >= 23) {
            for (String perm : mPermissions1) {
                if (PackageManager.PERMISSION_GRANTED != checkSelfPermission(perm)) {
                    return false;
                }
            }
        } else {
            return true;
        }
        return true;
    }
    //    是否获取了相机权限
    public boolean IsCamPermissionHave() {
        if (Build.VERSION.SDK_INT >= 23) {
            for (String perm : mPermissions2) {
                if (PackageManager.PERMISSION_GRANTED != checkSelfPermission(perm)) {
                    return false;
                }
            }
        } else {
            return true;
        }
        return true;
    }

    //    请求相机权限
    public void ReqCamPrem() {
        if (Build.VERSION.SDK_INT >= 23) {
            for (String perm : mPermissions2) {
                if (PackageManager.PERMISSION_GRANTED != checkSelfPermission(perm)) {
                    requestPermissions(mPermissions2, 0);
                }
            }
        } else {

        }
    }

    //     请求定位权限
    public void ReqDingWeiPrem() {
        if (Build.VERSION.SDK_INT >= 23) {
            for (String perm : mPermissions1) {
                if (PackageManager.PERMISSION_GRANTED != checkSelfPermission(perm)) {
                    requestPermissions(mPermissions1, 0);
                }
            }
        } else {

        }
    }

    //通过浏览器打开链接
    public void OpenUrlInBroswer(String url) {
        Uri uri = Uri.parse(url);
//        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
//        startActivity(intent);
        Intent intent = new Intent(MainActivity.this, WebViewActivity.class);
        intent.setData(uri);
        startActivity(intent);
    }

    //刷新资源
    public void RefreshFile(String path) {
        //说明第一个参数上下文，第二个参数是文件路径例如：/storage/emulated/0/1621832516463_1181875151.mp4 第三个参数是文件类型，传空代表自行根据文件后缀判断刷新到相册
        MediaScannerConnection.scanFile(MainActivity.this, new String[]{path}, null, new MediaScannerConnection.OnScanCompletedListener() {
            @Override
            public void onScanCompleted(String path, Uri uri) {
                //刷新成功的回调方法
                Log.e("资源刷新成功路径为", path);
            }
        });
    }



}